package io.grpc.examples.nameservers;

import static io.grpc.MethodDescriptor.generateFullMethodName;
import static io.grpc.stub.ClientCalls.asyncServerStreamingCall;
import static io.grpc.stub.ClientCalls.blockingServerStreamingCall;
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;

/**
 * <pre>
 * 定义服务
 * </pre>
 */
@javax.annotation.Generated(
    value = "by gRPC proto compiler (version 1.12.0)",
    comments = "Source: nameServers.proto")
public final class NameServersGrpc {

  private NameServersGrpc() {}

  public static final String SERVICE_NAME = "nameservers.NameServers";

  // Static method descriptors that strictly reflect the proto.
  @io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
  @Deprecated // Use {@link #getGetIpsByNameMethod()} instead.
  public static final io.grpc.MethodDescriptor<io.grpc.examples.nameservers.Name,
      io.grpc.examples.nameservers.Ip> METHOD_GET_IPS_BY_NAME = getGetIpsByNameMethodHelper();

  private static volatile io.grpc.MethodDescriptor<io.grpc.examples.nameservers.Name,
      io.grpc.examples.nameservers.Ip> getGetIpsByNameMethod;

  @io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
  public static io.grpc.MethodDescriptor<io.grpc.examples.nameservers.Name,
      io.grpc.examples.nameservers.Ip> getGetIpsByNameMethod() {
    return getGetIpsByNameMethodHelper();
  }

  private static io.grpc.MethodDescriptor<io.grpc.examples.nameservers.Name,
      io.grpc.examples.nameservers.Ip> getGetIpsByNameMethodHelper() {
    io.grpc.MethodDescriptor<io.grpc.examples.nameservers.Name, io.grpc.examples.nameservers.Ip> getGetIpsByNameMethod;
    if ((getGetIpsByNameMethod = NameServersGrpc.getGetIpsByNameMethod) == null) {
      synchronized (NameServersGrpc.class) {
        if ((getGetIpsByNameMethod = NameServersGrpc.getGetIpsByNameMethod) == null) {
          NameServersGrpc.getGetIpsByNameMethod = getGetIpsByNameMethod =
              io.grpc.MethodDescriptor.<io.grpc.examples.nameservers.Name, io.grpc.examples.nameservers.Ip>newBuilder()
              .setType(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING)
              .setFullMethodName(generateFullMethodName(
                  "nameservers.NameServers", "getIpsByName"))
              .setSampledToLocalTracing(true)
              .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
                  io.grpc.examples.nameservers.Name.getDefaultInstance()))
              .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
                  io.grpc.examples.nameservers.Ip.getDefaultInstance()))
                  .setSchemaDescriptor(new NameServersMethodDescriptorSupplier("getIpsByName"))
                  .build();
          }
        }
     }
     return getGetIpsByNameMethod;
  }

  /**
   * Creates a new async stub that supports all call types for the service
   */
  public static NameServersStub newStub(io.grpc.Channel channel) {
    return new NameServersStub(channel);
  }

  /**
   * Creates a new blocking-style stub that supports unary and streaming output calls on the service
   */
  public static NameServersBlockingStub newBlockingStub(
      io.grpc.Channel channel) {
    return new NameServersBlockingStub(channel);
  }

  /**
   * Creates a new ListenableFuture-style stub that supports unary calls on the service
   */
  public static NameServersFutureStub newFutureStub(
      io.grpc.Channel channel) {
    return new NameServersFutureStub(channel);
  }

  /**
   * <pre>
   * 定义服务
   * </pre>
   */
  public static abstract class NameServersImplBase implements io.grpc.BindableService {

    /**
     * <pre>
     * 服务中的方法，用于根据Name类型的参数获得一系列ip，以流的方式返回
     * </pre>
     */
    public void getIpsByName(io.grpc.examples.nameservers.Name request,
        io.grpc.stub.StreamObserver<io.grpc.examples.nameservers.Ip> responseObserver) {
      asyncUnimplementedUnaryCall(getGetIpsByNameMethodHelper(), responseObserver);
    }

    @Override public final io.grpc.ServerServiceDefinition bindService() {
      return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
          .addMethod(
            getGetIpsByNameMethodHelper(),
            asyncServerStreamingCall(
              new MethodHandlers<
                io.grpc.examples.nameservers.Name,
                io.grpc.examples.nameservers.Ip>(
                  this, METHODID_GET_IPS_BY_NAME)))
          .build();
    }
  }

  /**
   * <pre>
   * 定义服务
   * </pre>
   */
  public static final class NameServersStub extends io.grpc.stub.AbstractStub<NameServersStub> {
    private NameServersStub(io.grpc.Channel channel) {
      super(channel);
    }

    private NameServersStub(io.grpc.Channel channel,
        io.grpc.CallOptions callOptions) {
      super(channel, callOptions);
    }

    @Override
    protected NameServersStub build(io.grpc.Channel channel,
        io.grpc.CallOptions callOptions) {
      return new NameServersStub(channel, callOptions);
    }

    /**
     * <pre>
     * 服务中的方法，用于根据Name类型的参数获得一系列ip，以流的方式返回
     * </pre>
     */
    public void getIpsByName(io.grpc.examples.nameservers.Name request,
        io.grpc.stub.StreamObserver<io.grpc.examples.nameservers.Ip> responseObserver) {
      asyncServerStreamingCall(
          getChannel().newCall(getGetIpsByNameMethodHelper(), getCallOptions()), request, responseObserver);
    }
  }

  /**
   * <pre>
   * 定义服务
   * </pre>
   */
  public static final class NameServersBlockingStub extends io.grpc.stub.AbstractStub<NameServersBlockingStub> {
    private NameServersBlockingStub(io.grpc.Channel channel) {
      super(channel);
    }

    private NameServersBlockingStub(io.grpc.Channel channel,
        io.grpc.CallOptions callOptions) {
      super(channel, callOptions);
    }

    @Override
    protected NameServersBlockingStub build(io.grpc.Channel channel,
        io.grpc.CallOptions callOptions) {
      return new NameServersBlockingStub(channel, callOptions);
    }

    /**
     * <pre>
     * 服务中的方法，用于根据Name类型的参数获得一系列ip，以流的方式返回
     * </pre>
     */
    public java.util.Iterator<io.grpc.examples.nameservers.Ip> getIpsByName(
        io.grpc.examples.nameservers.Name request) {
      return blockingServerStreamingCall(
          getChannel(), getGetIpsByNameMethodHelper(), getCallOptions(), request);
    }
  }

  /**
   * <pre>
   * 定义服务
   * </pre>
   */
  public static final class NameServersFutureStub extends io.grpc.stub.AbstractStub<NameServersFutureStub> {
    private NameServersFutureStub(io.grpc.Channel channel) {
      super(channel);
    }

    private NameServersFutureStub(io.grpc.Channel channel,
        io.grpc.CallOptions callOptions) {
      super(channel, callOptions);
    }

    @Override
    protected NameServersFutureStub build(io.grpc.Channel channel,
        io.grpc.CallOptions callOptions) {
      return new NameServersFutureStub(channel, callOptions);
    }
  }

  private static final int METHODID_GET_IPS_BY_NAME = 0;

  private static final class MethodHandlers<Req, Resp> implements
      io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
      io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
      io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
      io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
    private final NameServersImplBase serviceImpl;
    private final int methodId;

    MethodHandlers(NameServersImplBase serviceImpl, int methodId) {
      this.serviceImpl = serviceImpl;
      this.methodId = methodId;
    }

    @Override
    @SuppressWarnings("unchecked")
    public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {
      switch (methodId) {
        case METHODID_GET_IPS_BY_NAME:
          serviceImpl.getIpsByName((io.grpc.examples.nameservers.Name) request,
              (io.grpc.stub.StreamObserver<io.grpc.examples.nameservers.Ip>) responseObserver);
          break;
        default:
          throw new AssertionError();
      }
    }

    @Override
    @SuppressWarnings("unchecked")
    public io.grpc.stub.StreamObserver<Req> invoke(
        io.grpc.stub.StreamObserver<Resp> responseObserver) {
      switch (methodId) {
        default:
          throw new AssertionError();
      }
    }
  }

  private static abstract class NameServersBaseDescriptorSupplier
      implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier {
    NameServersBaseDescriptorSupplier() {}

    @Override
    public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {
      return io.grpc.examples.nameservers.NameProto.getDescriptor();
    }

    @Override
    public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() {
      return getFileDescriptor().findServiceByName("NameServers");
    }
  }

  private static final class NameServersFileDescriptorSupplier
      extends NameServersBaseDescriptorSupplier {
    NameServersFileDescriptorSupplier() {}
  }

  private static final class NameServersMethodDescriptorSupplier
      extends NameServersBaseDescriptorSupplier
      implements io.grpc.protobuf.ProtoMethodDescriptorSupplier {
    private final String methodName;

    NameServersMethodDescriptorSupplier(String methodName) {
      this.methodName = methodName;
    }

    @Override
    public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() {
      return getServiceDescriptor().findMethodByName(methodName);
    }
  }

  private static volatile io.grpc.ServiceDescriptor serviceDescriptor;

  public static io.grpc.ServiceDescriptor getServiceDescriptor() {
    io.grpc.ServiceDescriptor result = serviceDescriptor;
    if (result == null) {
      synchronized (NameServersGrpc.class) {
        result = serviceDescriptor;
        if (result == null) {
          serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME)
              .setSchemaDescriptor(new NameServersFileDescriptorSupplier())
              .addMethod(getGetIpsByNameMethodHelper())
              .build();
        }
      }
    }
    return result;
  }
}
